/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import functions.Dogs;
import functions.Users;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JArik
 */
public class User {
    private String name;
    private String surname;
    private Date visitDate;
    private String telef;
    private String email;
    private String breed;
    private String nick;
    private int dogId;
    private int id;
    private Dog dog;
    // address
    private String [] address;
    // ^^^^^^^^^^^^^^

    public User() {
    }

    public User(int setId)
    {
        id = setId;
    }
    public User(int setId, String setName, String setSurname, int nDogId, String nBreed, String nNick)
    {
        id = setId;
        name = setName;
        surname = setSurname;
        breed = nBreed;
        nick = nNick;
        dogId = nDogId;
    }
    public User(int setId, String setName, String setSurname)
    {
        id = setId;
        name = setName;
        surname = setSurname;
    }
    public User(int setId, String setName, String setSurname,Dog nDog)
    {
        id = setId;
        name = setName;
        surname = setSurname;
        dog = nDog;
    }


    public void setAddress(String nAdr)
    {
        if(nAdr != null)
        address = nAdr.split("(\r\n)");
    }
    public int getDogId()
    {
        return dogId;
    }
    public String getDogName()
    {
        if(nick !=null)
           return breed + "(" + nick + ")";
        else
           return breed;
    }
    public Dog getDog()
    {
          return dog;
    }
    public void setDog(Dog d)
    {
        dog = d;
    }
    public String getSurname()
    {
        return surname;
    }
    public String getName()
    {
        return name;
    }
    public String getFullName()
    {
        return surname.isEmpty() ? name:surname + " " + name;
    }
    public ArrayList<Dog> getDogs() throws SQLException
    {
        return Dogs.getByUserId(id);
    }
        public void setEmail(String email) {
        this.email = email;
    }

    public void setTelef(String telef) {
        this.telef = telef;
    }

    public int getId()
    {
        return id;
    }
    public String getStreet()
    {
        if (address!=null && address.length > 0 && address[0]!=null
                && !address[0].isEmpty())
             return address[0];
        else
            return "Адрес не указан";
    }
    public String [] getRawAddress()
    {
        return address;
    }
    public String getFullAddress()
    {
       try {
           if(address == null)
              setAddress(Users.getAddressById(id));
        } catch (SQLException ex) {
            return "Адрес не указан";
        }
        
        if (address!=null && address.length >0 && address[0]!=null
                && !address[0].isEmpty())
        {
            String adr="";
            int i=0;
            for(i=0; i< address.length-1; i++)
                if(!address[i].isEmpty())
                adr += address[i]+ "\n";
            adr += address[i++];
            return adr;
        }
        else
            return "Адрес не указан";


    }
    public String getTel()
    {
        if(telef != null)
            return telef;
        return "";
    }
    public String getEmail()
    {
        if(email != null)
            return email;
        return "";
    }
    public String toString()
    {
        if(surname != null && !surname.isEmpty())
          return surname + " " + name;
        else
          return name;
    }


}
